﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using _15EfCore反向工程.Migrations;

namespace _15EfCore反向工程.Context;

public partial class MyDbContext : DbContext
{
    public MyDbContext()
    {
    }

    public MyDbContext(DbContextOptions<MyDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<TBook> TBooks { get; set; }

    public virtual DbSet<TCat> TCats { get; set; }

    public virtual DbSet<TPerson> TPersons { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Server=Localhost;Database=efCorePractice;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=true;");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TBook>(entity =>
        {
            entity.ToTable("T_Books");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Author)
                .HasMaxLength(50)
                .HasDefaultValue("");
            entity.Property(e => e.Title).HasMaxLength(50);
        });

        modelBuilder.Entity<TCat>(entity =>
        {
            entity.ToTable("T_Cats");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Name).HasMaxLength(50);
        });

        modelBuilder.Entity<TPerson>(entity =>
        {
            entity.ToTable("T_Persons");

            entity.Property(e => e.Id).HasColumnName("ID");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
